#include "enemy1.h"
#include "config.h"

Enemy1::Enemy1()
{
    //加载资源
    m_Plane.load(ENEMY1_PATH);
    m_PlaneDown[0].load(ENEMY1_DOWN1);
    m_PlaneDown[1].load(ENEMY1_DOWN2);
    m_PlaneDown[2].load(ENEMY1_DOWN3);
    m_PlaneDown[3].load(ENEMY1_DOWN4);
    m_PlaneDown[4].load(ENEMY1_DOWN5);
    m_PlaneDown[5].load(ENEMY1_DOWN6);
    m_PlaneDown[6].load(ENEMY1_DOWN4);
    p_Plane = &m_Plane;

    //坐标
    m_X = 0;
    m_Y = 0;

    //速度
    m_Speed = ENEMY1_SPEED;

    //矩形框
    m_Rect.setWidth(m_Plane.width());
    m_Rect.setHeight(m_Plane.height());
    m_Rect.moveTo(m_X, m_Y);

    //是否闲置
    m_Free = true;

    //爆炸状态
    m_Down = -1;
}

/* 更新敌机坐标 */
void Enemy1::updatePosition()
{
    if(m_Free)
    {
        return;
    }
    //爆炸处理
    if(m_Down >= 0)
    {
        if(m_Down % ENEMY1_DOWN_INTERVAL == 0)
        {
            if(m_Down >= ENEMY1_DOWN_NUM*ENEMY1_DOWN_INTERVAL)
            {
                p_Plane = &m_Plane;
                m_Down = -1;
                m_Free = true;
                return;
            }
            else
            {
                p_Plane = &m_PlaneDown[m_Down/ENEMY1_DOWN_INTERVAL];
            }
        }
        m_Down++;
        return;
    }

    m_Y += m_Speed;
    m_Rect.moveTo(m_X, m_Y);

    if(m_Y > GAME_HEIGHT)
    {
        m_Free = true;
    }
}



